package com.pro.controller;

import java.beans.PropertyEditorSupport;
import java.sql.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import com.pro.param.ResponseParam;

public class BaseController {
	private ResponseParam responseParam;

	public ResponseParam getResponseParam() {
		if (responseParam == null) {
			responseParam = new ResponseParam();
		}
		return responseParam;
	}

	public  void setDataList1(List list){
		this.getResponseParam().setDataList1(list);
	}
	public void setMap(Map map){
		this.getResponseParam().setMap(map);
	}
	public void setResponseParam(ResponseParam responseParam) {
		this.responseParam = responseParam;
	}

	public void setData(Object object) {
		this.getResponseParam().setData(object);
	}
	public void setArray(int[][] array){
		this.getResponseParam().setArrays(array);
	}

	public void setDataList(List list) {
		this.getResponseParam().setDataList(list);
	}

	public void setMsg(String msg) {
		this.getResponseParam().setMsg(msg);
	}

	public void setSuccess(boolean success) {
		this.getResponseParam().setSuccess(success);
	}

	// public List<Menu> loadMenu(int id){
	// return "";
	// }
//	@org.springframework.web.bind.annotation.InitBinder
//	protected void InitBinder(WebDataBinder dataBinder) {
//		dataBinder.registerCustomEditor(Date.class,
//				new PropertyEditorSupport() {
//			
//					public void setAsText(String value) {
//						if(value==null || value.equals("")){
//							setValue("");
//						}
//						try {
//							setValue(new SimpleDateFormat("yyyy-MM-dd").parse(value));
//						} catch (ParseException e) {
//							setValue(null);
//						}
//					}
//
//					public String getAsText() {
//						return new SimpleDateFormat("yyyy-MM-dd")
//								.format((Date) getValue());
//					}
//
//				});
//	}
	@InitBinder
	protected void initBinder(HttpServletRequest request,
			ServletRequestDataBinder binder) throws Exception {
		DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		fmt.setLenient(true);
		CustomDateEditor dateEditor = new CustomDateEditor(fmt, true);
		binder.registerCustomEditor(Date.class, dateEditor);
//		super.initBinder(request, binder);
	}
}
